#pragma once

#include "../RHIResource.h"

class ColorBlendAttachment : public RHIResource
{
	friend class RenderState;

	struct BuilderDetails {

		VkPipelineColorBlendAttachmentState colorBlendAttachment;

		BuilderDetails()
		{
			colorBlendAttachment = {};

			colorBlendAttachment.blendEnable = VK_FALSE;
			colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
			colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
			colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
			colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
			colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
			colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
			colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
		}
	};

public:

	class Builder : public BuilderBase<BuilderDetails> {
		friend struct BuilderDetails;
	public:
		Builder() noexcept = default;
		Builder(Builder const& rhs) noexcept = default;
		Builder(Builder&& rhs) noexcept = default;
		~Builder() noexcept = default;
		Builder& operator=(Builder const& rhs) noexcept = default;
		Builder& operator=(Builder&& rhs) noexcept = default;

		Builder& SetBlendEnable(VkBool32 blendEnable) noexcept;
		Builder& SetSrcColorBlendFactor(VkBlendFactor srcColorBlendFactor) noexcept;
		Builder& SetDstColorBlendFactor(VkBlendFactor dstColorBlendFactor) noexcept;
		Builder& SetColorBlendOp(VkBlendOp colorBlendOp) noexcept;
		Builder& SetSrcAlphaBlendFactor(VkBlendFactor srcAlphaBlendFactor) noexcept;
		Builder& SetDstAlphaBlendFactor(VkBlendFactor dstAlphaBlendFactor) noexcept;
		Builder& SetAlphaBlendOp(VkBlendOp alphaBlendOp) noexcept;
		Builder& SetColorWriteMask(VkBlendOp alphaBlendOp) noexcept;

		RefCountPtr<ColorBlendAttachment> Build();

		uint32 GetHash() const;

	private:
		friend class ColorBlendAttachment;
	};

	ColorBlendAttachment(BuilderDetails& buildDetails);

	VkPipelineColorBlendAttachmentState GetColorBlendAttachment() const;

	virtual void ReleaseResource();

protected:

	VkPipelineColorBlendAttachmentState mColorBlendAttachment;
};